#include <algorithm>
#include <vector>
#include <cmath>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cstdlib>
#define LL long long
#define ldb long double
const ldb eps = 1e-9;
const ldb pi = fabsl(atan2(0.0, -1.0));
const int INF = 0x7f7f7f7f;
const LL LINF = 1ll << 60;
const ldb LDINF = 1e42;
#define nextLine() {int c = 0; while ((c = getchar()) != 10 && c != EOF);}
#define fill(a, c) memset(a, c, sizeof a)
#define debug(a) cerr << #a << " " << a << " ";
#define debugl(a) cerr << #a << " " << a << "\n";
#define addEdge(a, b) next[edges] = first[a]; first[a] = edges; end[edges] = b; edges++;
#define y0 y6
using namespace std;

int n;
int x[100010], y[100010];
int r[100010];
int x0, y0;

void Load()
{
	cin >> n;
	int i;
	for (i = 0; i < n; i++)
	{
		scanf("%d%d", &x[i], &y[i]);
		
	}
	reverse(x, x + n);
	reverse(y, y + n);
}

void Solve()
{
	int i;
	int j;
	for (i = 0; i < n; i++)
	{
		j = (i + 1 >= n) ? 0 : i + 1;
		if (((LL)x[j] - x[i]) * ((LL)y0 - y[i]) - ((LL)y[j] - y[i]) * ((LL)x0 - x[i]) < 0ll) break;
	}
	if (i < n)
	{
		cout << "0\n";
		return;
	}
	for (i = 0, j = 1; i < n; i++, j = (j + 1 >= n) ? 0 : j + 1)
	{
		while (((LL)x[j] - x[i]) * ((LL)y0 - y[i]) - ((LL)y[j] - y[i]) * ((LL)x0 - x[i]) > 0ll) j = (j + 1) % n;
		j--;
		if (j < 0) j = n - 1;
		r[i] = j;
	}
	LL res = (LL)n * ((LL)n - 1) * ((LL)n - 2) / 6ll;
	for (i = 0; i < n; i++)
	{
		if (r[i] < i)
		{
			res -= ((LL)r[i] + n - i) * ((LL)r[i] + n - i - 1) / 2ll;
		}
		else
		{
			res -= ((LL)r[i] - i) * ((LL)r[i] - i - 1) / 2ll;
		}
	}
	cout << res << "\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#endif
	Load();
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> x0 >> y0;
		Solve();
	}
	return 0;
}